﻿
@{
    ViewBag.Title = "单图文消息管理";
}
@section css
{
    <link href="/Content/scripts/zyupload/bootstrap.css" rel="stylesheet" />
    <link href="/Content/scripts/fileinput/css/bootstrap-fileupload.css" rel="stylesheet" />
    <link href="/Content/css/imageText/main.css" rel="stylesheet" />
}

<form id="editfrom">
    <div class="ct_box box_radius left">
        <div class="ct_banner">
            <span id="span_image">封面图片</span>
            <p id="span_title">标题</p>
            <div class="ban_bj">
                <a href="javascript:void(0)" onclick="editmain()">
                    <img src="/content/images/wechat/ico005.pngs" />
                </a>
            </div>
        </div>
        <div class="ct_duo" id="divsubimagetext">
        </div>
        <div class="ct_tj" onclick="addsubimagetext()" style="cursor: pointer;"></div>
        <div class="clear"></div>
    </div>
    <!--box -->

    <div class="bj_box box_radius">
        <i class="jt_out"></i>
        <i class="jt_in"></i>
        <input type="hidden" name="Id" id="txt_Id" value="@ViewBag.imageTextId" />
        <div class="bj_dan">
            <h3>标题</h3>
            <input name="Title" type="text" id="txt_title" />
        </div>
        <div class="bj_dan">
            <h3>内容摘要</h3>
            <input name="Descriptions" type="text" id="txt_Descriptions" />
        </div>
        <div class="bj_dan">
            <h3>
                <span class="left">封面</span>
                <span class="right">
                    <b>建议尺寸：540像素 * 300像素</b>
                </span>
                <div class="clear"></div>
            </h3>
            <input type="hidden" id="txt_PicUrl" name="PicUrl" />
        </div>
        <div id="fileupload" style="width: 300px;">
        </div>
        <div class="bj_dan">
            <h3>
                <span class="left">正文</span>
                <span class="right"></span>
                <div class="clear"></div>
            </h3>
            <textarea name="content" style="width: 100%; height: 250px"></textarea>
        </div>


        <div class="bj_dan">
            <h3>跳转链接</h3>
            <input name="RedictUrl" type="text" id="txt_RedictUrl" />
        </div>

        <div class="clear"></div>
    </div>

    <div class="clear"></div>

    <div class="bj_con">
        <a class="box_radius" href="/Wechat/ImageTextList">返回列表</a>
        <a class="box_radius" href="javascript:addImageText()">保存</a>
        <div class="clear"></div>
    </div>

</form>

@section scripts
{
    <script src="/Content/scripts/jquery.form.js"></script>
    <script src="/Content/kindeditor-4.1.2/kindeditor.js"></script>
    <script src="/Content/kindeditor-4.1.2/lang/zh_CN.js"></script>
    <script src="/Content/scripts/fileinput/js/bootstrap-fileupload.js"></script>
    <script>
        var layer;
        var editor;

        layui.use('layer', function () {
            layer = layui.layer;
        });

        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="content"]', {
                allowFileManager: false,
                items: [/*'fullscreen',*/'source', '|', 'undo', 'redo', '|', 'preview', 'insertorderedlist', 'insertunorderedlist', 'clearhtml', 'quickformat', 'selectall', '|',
                    'formatblock', '|', 'forecolor', 'hilitecolor', 'bold',
                    'italic', 'underline', 'removeformat', '|', 'image', 'multiimage',
                    'table', 'baidumap',
                    'anchor', 'link', 'unlink'],
                uploadJson: '/Content/kindeditor-4.1.2/asp.net/upload_json.ashx',
                afterCreate: function () {
                }
            });
        });

        function edit() {
            var url = "/Wechat/WechatMemuAjax?sub=getImageText";
            var id = $("#txt_Id").val();
            if (parseInt(id) > 0) {
                $.post(url, { "Id": id }, function (datas) {
                    var data = JSON.parse(datas)
                    if (data.status) {
                        var MsgTitle = data.data[0].title;
                        var MsgPic = data.data[0].picUrl;
                        var MsgDescriptions = data.data[0].descriptions;
                        var MsgRedictUrl = data.data[0].redictUrl;
                        if (MsgPic == "") {
                            $("#span_image").html("封面图片");
                        }
                        else {
                            $("#span_image").html("<img src=\"" + MsgPic + "\" />");
                        }
                        $("#span_title").html(MsgTitle);
                        $("#span_desc").html(MsgDescriptions);

                        $("#txt_title").val(MsgTitle);
                        $("#txt_RedictUrl").val(MsgRedictUrl);
                        $("#txt_Descriptions").val(MsgDescriptions);
                        $("#txt_PicUrl").val(MsgPic);
                        var pic = MsgPic;
                        if (pic != "") {
                            $('div[data-provides="fileupload"]').addClass("fileupload-exists").removeClass("fileupload-new");
                            $('.fileupload-preview').append("<img src='" + pic + "' style='width:100%'/>");
                        }
                        if (data.data[0].content) {
                            editor.html(data.data[0].content);
                        }

                    } else
                    {
                        layer.msg(data.message)
                    }

                }, "json");
            }

        }

        function addImageText() {
            editor.sync();
            var str = $("#editfrom").serialize();
            var url = "/Wechat/WechatMemuAjax?sub=insertOrUpdateImageText";
            $.post(url, str, function (datas) {
                var data = JSON.parse(datas)
                if (data.status) {
                    var url = "/Wechat/EditImageText?imageTextId=" + data.data;
                    location.href = url;
                }
                else {
                    layer.msg(data.message)
                }
            }, "json");

        }

        $(document).ready(function () {
            edit();
        });
    </script>
}
